<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./vue.js"></script>
  <script src="./vue-router.js"></script>
  <style>
    .active {
      color: red;
    }

    .box {
      width: 200px;
      height: 300px;
      position: absolute;
    }

    .position {
      background: yellowgreen
    }

    .search {
      background: rgb(79, 25, 228)
    }

    .my {
      background: rgb(247, 76, 118)
    }

    /* 左侧进入的第一帧 */
    .slide-left-enter,
    /* 从右侧进入后，离开的最后一帧 */
    .slide-right-leave-to {
      transform: translateX(-100%);
      opacity: 0;
    }

    .slide-left-enter-active,
    .slide-left-leave-active,
    .slide-right-enter-active,
    .slide-right-leave-active {
      transition: all 1s;
    }

    /* 左侧进入后，离开的最后一帧 */
    .slide-left-leave-to,
    /* 右侧进入的第一帧 */
    .slide-right-enter {
      transform: translateX(100%);
      opacity: 0;
    }
  </style>
</head>

<body>
  <div id="app">
    <ul>
      <router-link active-class="active" tag="li" to="/position">职位信息</router-link>
      <router-link active-class="active" tag="li" to="/search">搜索</router-link>
      <router-link active-class="active" tag="li" to="/my">我的</router-link>
    </ul>
    <div>
      <transition :name="transitionname">
        <router-view></router-view>
      </transition>
    </div>

  </div>

  <script>


    var routes = [
      {
        path: "/position",
        meta: { order: 1 },
        component: {
          template: `
          <div class="box position">职位信息</div>`
        }
      },
      {
        path: "/search",
        meta: { order: 2 },
        component: {
          template: `
          <div class="box search">搜索</div>` }
      },
      {
        path: "/my",
        meta: { order: 3 },
        component: {
          template: `
          <div class="box my">我的</div>` }
      }
    ]


    var router = new VueRouter({
      routes
    })


    var vm = new Vue({
      data: {
        transitionname: 'slide-left'
      },
      router,
      watch: {
        '$route'(to, from) {
          if (to.meta.order > from.meta.order) {
            this.transitionname = 'slide-right'
          } else {
            this.transitionname = 'slide-left'
          }
        }
      }
    }).$mount('#app')

  </script>

</body>

</html>